import {request} from "../../request/index.js";
Page({
    data:{
        searchGoods:[],
        isShow:false,
        inputValue:""
    },
    Timer:null,
    //输入框输入事件监听
    handleInput(e){
        // console.log(e);
        let {value}=e.detail;
        if(value.trim()){
            this.setData({
                isShow:true
            });
            clearTimeout(this.Timer);
            this.Timer=setTimeout(()=>{
                this.searchGoods(value);
            },1000);
        }else{
            clearTimeout(this.Timer);
            this.setData({
                isShow:false,
                searchGoods:[]
            });
        };
    },
    //搜索事件监听
    async searchGoods(value){
        let res=await request({url:"/goods/qsearch",data:{query:value}});
        // console.log(res);
        this.setData({
            searchGoods:res.data.message
        });
    },
    //点击取消按钮事件监听
    handleCancel(){
        this.setData({
            isShow:false,
            inputValue:"",
            searchGoods:[]
        });
    }
});